package com.rongma.waterdrop.network.api;

import android.content.Context;

import com.rongma.waterdrop.listener.getBmob.GetTimeListener;
import com.rongma.waterdrop.model.Time;
import com.rongma.waterdrop.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;

/**
 * Created by RongMa on 16/6/11.
 */

public class GetTimeAPI
{
    private GetTimeListener listener;

    public GetTimeAPI(GetTimeListener listener)
    {
        this.listener = listener;
    }

    //从网络获取所有的Time数据
    public void getDataFromBmob(final Context context)
    {
        new Thread(new Runnable() {
            @Override
            public void run() {
                BmobQuery<Time> timeBmobQuery = new BmobQuery<Time>();
                timeBmobQuery.order("createdAt");
                timeBmobQuery.findObjects(context, new FindListener<Time>() {
                    @Override
                    public void onSuccess(List<Time> list) {
                        listener.onSuccess((ArrayList<Time>) list);
                    }

                    @Override
                    public void onError(int i, String s){
                        listener.onError(s);
                    }
                });

            }
        }).start();
    }
}
